package com.java.study.utils;

import java.util.Random;

/**
 * ClassName:ToolUtils
 * Description:
 *
 * @Date:2022/9/6 10:25
 * @Author:chenruifeng
 */
public class ToolUtils {
    public static String randomString() {
        String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        Random random1 = new Random();
        //指定字符串长度，拼接字符并toString
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < 8; i++) {
            //获取指定长度的字符串中任意一个字符的索引值int number=random1.nextInt(str.length());
            int number = random1.nextInt(str.length());
            //根据索引值获取对应的字符char charAt = str.charAt(number);
            char charAt = str.charAt(number);
            sb.append(charAt);
        }
        String str1 = sb.toString();
        return str1;
    }
}
